package com.isnmp.nms.framework.discover.rstype;

import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import com.isnmp.common.snmp.SNMPFactory;
import com.isnmp.common.snmp.mib.MibSoftwareRunEntry;
import com.isnmp.nms.framework.discover.DeviceInfo;
import com.isnmp.nms.framework.discover.ResourceInfo;
import com.isnmp.nms.framework.discover.ResourceSearchMothType;

public class TCPServerType extends ResourceSearchMothType {
    public TCPServerType() {
        setResoureTypeName(Messages.getString("TCPServerType.0"));
    }

    public String getResourceSearchMoth() {
        return Messages.getString("TCPServerType.1");
    }

    public List<ResourceInfo> getResoureInfo(DeviceInfo paramDeviceInfo) {
        Vector localVector = new Vector();
        int i = 0;
        try {
            i = Integer.parseInt(getResourceRSID());
        } catch (Exception localException1) {
            localException1.printStackTrace();
            return localVector;
        }
        try {
            int j = 3000;
            Socket localSocket = new Socket();
            String str1 = paramDeviceInfo.getDeviceIP();
            if ((str1 == null) || (str1.equalsIgnoreCase("")))
                str1 = paramDeviceInfo.getSnmpTarget().nodeIP;
            InetSocketAddress localInetSocketAddress = new InetSocketAddress(str1, i);
            localSocket.connect(localInetSocketAddress, j);
            ResourceInfo localResourceInfo = new ResourceInfo();
            localResourceInfo.setLocalDevice(paramDeviceInfo);
            localResourceInfo.setResourceTypeName(getResoureTypeName());
            localResourceInfo.setResourceRSIDValue(getResourceRSID());
            localResourceInfo.setResourceName(getResoureTypeName());
            String str2 = getSoftName(paramDeviceInfo);
            if (str2 != null)
                localResourceInfo.setResourceDesc(str2);
            localVector.add(localResourceInfo);
        } catch (Exception localException2) {
        }
        return localVector;
    }

    private String getSoftName(DeviceInfo paramDeviceInfo) {
        try {
            if (paramDeviceInfo.getSnmpTarget() == null)
                return null;
            List localList = SNMPFactory.getSNMPAPI().getAllTableData(MibSoftwareRunEntry.class, paramDeviceInfo.getSnmpTarget());
            Iterator localIterator1 = this.typeSoftDescList.iterator();
            while (localIterator1.hasNext()) {
                String str = (String) localIterator1.next();
                Iterator localIterator2 = localList.iterator();
                while (localIterator2.hasNext()) {
                    MibSoftwareRunEntry localMibSoftwareRunEntry = (MibSoftwareRunEntry) localIterator2.next();
                    if (localMibSoftwareRunEntry.getHrSWRunName().indexOf(str) >= 0)
                        return str;
                }
            }
            return null;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        return null;
    }
}